/*
 * Copyright (c) 2009. Silenus Consultoria, S.L.
 */
package es.silenus.detecta.model;

import java.util.HashSet;
import java.util.Set;


/**
 * Province of an Autonomy.  Persistent class, read-only.
 *
 * @author <a href="mailto:malonso@silenus-consultoria.es">Mariano Alonso</a>
 *
 * @since 22-mar-2009 11:04:04
 */
public class Province implements java.io.Serializable {
	/**
	 * The identifier.
	 */
	private String id;

	/**
	 * The name.
	 */
	private String name;

	/**
	 * The parent autonomy.
	 */
	private Autonomy autonomy;

	/**
	 * The organizations this province is associated to.
	 */
	private Set<Organization> organizations;

	/**
	 * The councils this province owns.
	 */
	private Set<Council> councils;

/**
   * Constructor.
   */
	public Province() {
		councils = new HashSet<Council>();
	}

	/**
	 * Retrieves the identifier.
	 *
	 * @return the identifier.
	 */
	public String getId() {
		return this.id;
	}

	/**
	 * Sets the identifier.
	 *
	 * @param id the identifier.
	 */
	public void setId(final String id) {
		this.id = id;
	}

	/**
	 * Retrieves the name.
	 *
	 * @return the name.
	 */
	public String getName() {
		return this.name;
	}

	/**
	 * Sets the name.
	 *
	 * @param name the name.
	 */
	public void setName(final String name) {
		this.name = name;
	}

	/**
	 * Retrieves the autonomy.
	 *
	 * @return the autonomy.
	 */
	public Autonomy getAutonomy() {
		return this.autonomy;
	}

	/**
	 * Sets the autonomy.
	 *
	 * @param autonomy the autonomy.
	 */
	public void setAutonomy(final Autonomy autonomy) {
		this.autonomy = autonomy;
	}

	/**
	 * Retrieves the councils.
	 *
	 * @return the councils.
	 */
	public Set<Council> getCouncils() {
		return this.councils;
	}

	/**
	 * Retrieves the organizations.
	 *
	 * @return the organizations.
	 */
	public Set<Organization> getOrganizations() {
		return organizations;
	}

	/**
	 * Sets the organizations.
	 *
	 * @param organizations the organizations.
	 */
	public void setOrganizations(final Set<Organization> organizations) {
		this.organizations = organizations;
	}

	/**
	 * Sets the councils.
	 *
	 * @param councils the councils.
	 */
	public void setCouncils(final Set<Council> councils) {
		this.councils = councils;
	}

	/**
	 * Checks if objects are equal.
	 *
	 * @param o other object.
	 *
	 * @return true if equal, false otherwise.
	 */
	@Override
	public boolean equals(Object o) {
		if(this == o) {
			return true;
		}

		if(!(o instanceof Province)) {
			return false;
		}

		Province province = (Province)o;

		if((getId() != null) ? (!getId().equals(province.getId())) : (province.getId() != null)) {
			return false;
		}

		return true;
	}

	/**
	 * Calculates the hash of this instance.
	 *
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		return (getId() != null) ? getId().hashCode() : 0;
	}

	/**
	 * Stringifies this instance.
	 *
	 * @return the string representation.
	 */
	@Override
	public String toString() {
		final StringBuilder sb = new StringBuilder();

		sb.append("Province");
		sb.append("{id='").append(getId()).append('\'');
		sb.append(", name='").append(getName()).append('\'');
		sb.append('}');

		return sb.toString();
	}
}
